package top.jiangqiang.qianyi.business.service.impl;

import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import top.jiangqiang.qianyi.business.mapstruct.AdminUserAndUserInfoToAdminUserDetails;
import top.jiangqiang.qianyi.business.service.AdminUserService;
import top.jiangqiang.qianyi.business.service.UserInfoService;
import top.jiangqiang.qianyi.common.auth.model.UserDetails;
import top.jiangqiang.qianyi.common.auth.service.UserDetailService;
import top.jiangqiang.qianyi.common.constants.auth.Platform;
import top.jiangqiang.qianyi.data.model.entity.AdminUser;
import top.jiangqiang.qianyi.data.model.entity.UserInfo;

@Service
@RequiredArgsConstructor
public class DefaultUserDetailService implements UserDetailService {
    private final AdminUserService adminUserService;
    private final UserInfoService userInfoService;
    private final AdminUserAndUserInfoToAdminUserDetails adminUserAndUserInfoToAdminUserDetails;

    @Override
    public UserDetails getUserDetails(@NotNull Long userId, Platform platform) {
        AdminUser adminUser = adminUserService.getById(userId);
        UserInfo userInfo = userInfoService.getById(adminUser.getUserId());
        return adminUserAndUserInfoToAdminUserDetails.convert(adminUser, userInfo);
    }
}
